<?php
    /**
    * View detail Real Estate project
    * @author trungdt
    * @since June 25, 2011
    * 
    * Change logs
    * 
    */

    if (!defined('EXPONENT')) exit;
    define('AB_HTML_NULL',"<p>&#160;</p>");
    
    global $db;
    $id=-1;
    $sql_where="";
    if (isset($_REQUEST['id']))
    {
        $id=$_REQUEST['id'];
        if (is_int($id))
        {
            $id=intval($id);
            $sql_where=" id = {$id}";
        }
        else
        {
            $id=_ab_safe_html_string($id);
            $sql_where=" shortname = '{$id}'";
        }

        $config=$db->selectObject("duanmodule_config","location_data = '".serialize($loc)."'");

        $template = new template('duanmodule',"_view_detail",$loc);

        $project= $db->selectObject('duan'," location_data='".serialize($loc)."' AND {$sql_where} ");

        if ($project && (
                // if not public, but have permission
                (($project->pstate == 0) && (exponent_permissions_check('administrate',$loc) || 
                exponent_permissions_check('edit',$loc) ||
                exponent_permissions_check('create',$loc)))
                || ($project->pstate == 1)
            )
        )
        {
            //location
            $province=duanmodule::_GetProvince_byID(intval($project->province_id));
            $ward = duanmodule::_GetWard_byID(intval($project->province_ward_id), ($project->province_id));
            $project->location=$ward->name ." - ".$province->name;
            
            // for any html text field, we must ensure that every field can not be a blank field, by check content contain &#160; or not
            if (trim($project->tongquan) == AB_HTML_NULL)
            {$project->tongquan="";}
            
            if (trim($project->hatang_dichvu) == AB_HTML_NULL)
            {$project->hatang_dichvu="";}
            
            if (trim($project->vitri_chitiet) == AB_HTML_NULL)
            {$project->vitri_chitiet="";}
            
            if (trim($project->ttthem_sodomatbang) == AB_HTML_NULL)
            {$project->ttthem_sodomatbang="";}
            
            if (trim($project->ttthem_maunha) == AB_HTML_NULL)
            {$project->ttthem_maunha="";}
            
            if (trim($project->ttthem_thanhtoan) == AB_HTML_NULL)
            {$project->ttthem_thanhtoan="";}
            
            // for thumbnail
            if ($project->thumbnail <= 0) {
                $project->thumbnail_path = '';
            } else {
                $file = $db->selectObject('file', 'id='.$project->thumbnail);
                $project->thumbnail_path = BASE_URL."/".$file->directory.'/'.$file->filename;
                _ab_theme_og_meta_set($project->thumbnail_path,2); // set OG image
            }
            // for big image
            if ($project->big_image <= 0) {
                $project->bigimage_path = '';
            } else {
                $file = $db->selectObject('file', 'id='.$project->big_image);
                $project->bigimage_path = BASE_URL."/".$file->directory.'/'.$file->filename;
            }


            $template->register_permissions(array('administrate','configure','edit','create','delete'),$loc);
            _ab_theme_action_register_title($project->name,1,1);
            _ab_theme_action_register_title(strip_tags($project->seo_des),1,0);
            $template->assign('project', $project);
            $template->assign('config', $config);

            exponent_flow_set(SYS_FLOW_PUBLIC,SYS_FLOW_ACTION);
            $template->output();
        }
        else
        {
            echo SITE_404_HTML;
        }
    }
    else
    {
        // For SEO purpose, we must list all project
        // in-case, we dont have ID, call action list to show all projects
        // list all project (for management only - hehe)
        $_REQUEST['page']=1;
        include("list.php");
    }


?>
